package com.hzdl.car.controller;

import com.github.pagehelper.PageInfo;
import com.hzdl.car.service.LogService;
import com.hzdl.car.util.AJAXResult;
import com.hzdl.car.vo.LogVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/log")
public class LogController {
    @Autowired
    private LogService ls;

    @RequestMapping("/logInit")
    public String logInit(){
        return "/system/log";
    }

    @RequestMapping("/logShow")
    @ResponseBody
    public AJAXResult logShow(LogVo logVo){
        if(logVo.getPage()==null){
            logVo.setPage(1);
        }
        if(logVo.getLimit()==null){
            logVo.setLimit(5);
        }
        PageInfo pageInfo=ls.findLogByWhere(logVo);
        return new AJAXResult(0,"",pageInfo.getList(),pageInfo.getTotal());

    }
    @RequestMapping("/deleteAllLog")
    @ResponseBody
    public AJAXResult deleteAllLog(String ids){
        String[] id = ids.split(",");
        int row=0;
        for(int i = 0;i<id.length;i++){
            row+=ls.deleteAllLog(Integer.valueOf(id[i]));
        }
        if(row==0){
            return AJAXResult.DELETE_ERROR;
        }
        return AJAXResult.DELETE_SUCCESS;
    }
    @RequestMapping("/logDelete")
    @ResponseBody
    public AJAXResult logDelete(String logid){
        int row=ls.deleteAllLog(Integer.valueOf(logid));
        if(row==0){
            return AJAXResult.DELETE_ERROR;
        }
        return AJAXResult.DELETE_SUCCESS;
    }

}
